import 'package:flutter/material.dart';

enum IconPosition {
  left,
  right,
  top,
  bottom,
}

class IconTextButton extends StatelessWidget {
  final Widget icon;
  final Text text;
  final EdgeInsets? margin;
  final double space;
  final Function? onPressed;
  final IconPosition iconPosition;

  const IconTextButton(this.icon, this.text,
      {this.iconPosition = IconPosition.top,
      this.margin,
      this.space = 5,
      this.onPressed});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTap: () {
          onPressed?.call();
        },
        child: _widget());
  }

  _widget() {
    switch (iconPosition) {
      case IconPosition.top:
        return Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            icon,
            SizedBox(
              height: space,
            ),
            text
          ],
        );
      case IconPosition.bottom:
        return Column(
          children: [
            text,
            SizedBox(
              height: space,
            ),
            icon
          ],
        );

      case IconPosition.left:
        return Row(
          children: [
            icon,
            SizedBox(
              width: space,
            ),
            text,
          ],
        );
      case IconPosition.right:
        return Row(
          children: [
            text,
            SizedBox(
              width: space,
            ),
            icon,
          ],
        );
    }
  }
}
